package day04;

import java.util.Random;
import java.util.Scanner;

/**
 * @author yzg
 * @desc TODO
 * @date 2025/4/11
 */
public class GroupScoreAnalyze {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.print("请输入班级总组数:");
        int groupCount = sc.nextInt();
        System.out.print("请输入班级中每组的人数:");
        int studentPerGroup = sc.nextInt();

        int[][] scores = new int[groupCount][studentPerGroup];
        Random random = new Random();

        for (int i = 0; i < groupCount; i++) {
            for (int j = 0; j < studentPerGroup; j++) {
                scores[i][j] = random.nextInt(101);
            }
        }

        int[] failCount = new int[groupCount]; // 每组不及格人数
        double[] avgScore = new double[groupCount]; // 每组平均分
        int totalFailCount = 0; // 班级总不及格人数
        double totalAvgScore = 0; // 班级总平均分
        double maxGroupAvg = 0; // 组的最高平均分

        // 计算每组数据
        for (int i = 0; i < groupCount; i++) {
            int groupSum = 0;
            int groupFailCount = 0;

            for (int j = 0; j < studentPerGroup; j++) {
                groupSum += scores[i][j];
                if (scores[i][j] < 60) {
                    groupFailCount++;
                }
            }

            failCount[i] = groupFailCount;
            avgScore[i] = (double) groupSum / studentPerGroup;
            totalFailCount += groupFailCount;
            totalAvgScore += groupSum;

            if (avgScore[i] > maxGroupAvg) {
                maxGroupAvg = avgScore[i];
            }
        }

        // 计算班级总平均分
        totalAvgScore /= (groupCount * studentPerGroup);

        // 打印结果
        for (int i = 0; i < groupCount; i++) {
            System.out.println("第" + (i + 1) + "组不及格人数为: "+ failCount[i] +" 人");
            System.out.println("第" + (i + 1) + "组平均分为: " +  (int) avgScore[i]);
        }

        System.out.println("班级中单组最高平均分为: "+ (int)maxGroupAvg);
        System.out.println("班级中不及格人数为: " + totalFailCount + " 人");
        System.out.println("班级总平均分为: " + (int)totalAvgScore);
    }
}
